package vip.zhy.faststart.demo.controller;

import jakarta.servlet.http.HttpServletResponse;
import jakarta.validation.Valid;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import vip.zhy.faststart.demo.param.UserLoginParam;
import vip.zhy.faststart.framework.domain.Response;
import vip.zhy.faststart.framework.interceptor.TokenInterceptor;
import vip.zhy.faststart.framework.jwt.Jwt;


@Slf4j
@RestController
@RequestMapping("/login")
public class LoginController {

    @PostMapping
    public Response<?> login(@RequestBody @Valid UserLoginParam param, HttpServletResponse response) {
        log.info("UserLoginParam = {}", param);
        String token = Jwt.create(param.getUsername());
        response.setHeader(TokenInterceptor.TOKEN_NAME, token);
        return Response.ok();
    }

}
